<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/inc/common.jsp"%>
<html>
<head>
<title>后台管理</title>
<!--jqzoom css  -->
<link rel="stylesheet" type="text/css" href="${basePath}/css/pic/jqzoom.css" />
<!--jqzoom js  -->
<script type="text/javascript" src="${basePath}/js/pic/jquery.jqzoom.js" ></script>
<script type="text/javascript" src="${basePath}/js/pic/jqzoom.init.js" ></script>

</head>
<body class="easyui-layout"  data-options="fit:true">
	<div  data-options="region:'center',title:'车辆放行卡',footer:'#searchfooter'" >
		<div class="easyui-layout" data-options="fit:true" >
			<div data-options="title:'',region:'west'," style="width:30%;">
				<div class="easyui-panel" data-options="title:'',fit:true"  style="padding:5px 5px 5px 5px;"  border=false>
			     <form id="editForm" method="post" >
			     	<input id="id" name="id" type="hidden" value="${cardRelease.id}">
			     	<input id="serialNo" name="serialNo" type="hidden" value="${cardRelease.serialNo}">
			     	<input type="hidden" id="showState" name="showState" value="1">
			    	<table  style="width:100%;" cellpadding="0" cellspacing="1"  class="formtable">
			    		<tr>
				    		<td align="right" style="width: 30%">流水号:</td>
							<td class="value">
								<input class="easyui-textbox" type="text" value="${cardRelease.serialNo}" disabled="disabled">
							</td>
						</tr>
						<tr>
				    		<td align="right" style="width: 30%">车牌号:</td>
							<td class="value">
								<input class="easyui-textbox" type="text" name="carNo" id="carNo" value="${cardRelease.carNo}" data-options="required:true" >
							</td>
						</tr>
						<tr>
				    		<td align="right" style="width: 30%">中国旅客人数:</td>
							<td class="value">
								<input class="easyui-numberbox" type="text" name="chineseNum" id="chineseNum" value="${cardRelease.chineseNum}"  data-options="required:true">
							</td>
						</tr>
						<tr>
				    		<td align="right" style="width: 30%">外国旅客人数:</td>
							<td class="value">
								<input class="easyui-numberbox" type="text" name="foreignNum" id="foreignNum" value="${cardRelease.foreignNum}"  data-options="required:true">
							</td>
						</tr>
						<tr>
				    		<td align="right" style="width: 30%">总人数:</td>
							<td class="value">
								<input class="easyui-numberbox" type="text" name="totalNum" id="totalNum" value="${cardRelease.totalNum}"  readonly="readonly">
							</td>
						</tr>
						<tr>
				    		<td align="right" style="width: 30%">国籍:</td>
							<td class="value">
								<input class="easyui-combobox" name="nationality" id="nationality" value="${cardRelease.nationality}" data-options="url:'${basePath}/sys/dictionary/dicbykey.do?key=1005',method:'get',valueField:'dataCode',textField:'dataName',panelHeight:'auto',editable:false,required:true" >
							</td>
						</tr>
						<tr>
				    		<td align="right" style="width: 30%">入境时间:</td>
							<td class="value">
								<input class="easyui-datetimebox" type="text" id="entryTime" name="entryTime" value="${cardRelease.entryTime}" readonly="readonly">
							</td>
						</tr>
			    		<tr>
			    			<td align="right" style="width: 30%">车辆类型:</td>
							<td class="value">
								<input class="easyui-combobox" name="carType" id="carType" value="${cardRelease.carType}" data-options="url:'${basePath}/sys/dictionary/dicbykey.do?key=1009',method:'get',valueField:'dataCode',textField:'dataName',panelHeight:'auto',editable:false,required:true" >
							</td>
			    		</tr>
			    		<tr>
			    			<td align="right" style="width: 30%">出入境类型:</td>
							<td class="value">
								<input class="easyui-combobox" name="entryExitType" id="entryExitType" value="${cardRelease.entryExitType}" data-options="url:'${basePath}/sys/dictionary/dicbykey.do?key=1011&type=1',method:'get',valueField:'dataCode',textField:'dataName',panelHeight:'auto',editable:false,readonly:true" >
							</td>
			    		</tr>
			    		<tr>
			    			<td align="right" style="width: 30%">备注:</td>
							<td class="value">
								<input class="easyui-textbox" name="remark" id="remark" value="${cardRelease.remark}" data-options="multiline:true" style="height:118px" type="text">
							</td>
			    		</tr>
			    	</table>
			    </form>
		    </div>
			</div>
			<div data-options="region:'center'" >
				<div class="easyui-panel" data-options="title:'',fit:true"  style="padding:5px 5px 5px 5px;"  border=false>
			    	<table id="picTable" style="width:100%;" cellpadding="0" cellspacing="1" class="formtable">
			    		<tr>
			    			<td align="center" style="width: 15%">正面</td>
			    			<td class="value">
		    					<div class="jqzoomright">
 									<img id="zm" class="sampleimage" src="" jqimg="" />
								</div>
			    			</td>
			    			<td align="center" style="width: 15%">侧后面45度</td>
			    			<td class="value">
		    					<div  class="jqzoomleft">
 									<img id="ch" class="sampleimage" src="" jqimg="" />
								</div>
			    			</td>
			    		</tr>
			    		<tr>
			    			<td align="center">侧前45度</td>
			    			<td class="value">
		    					<div  class="jqzoomright">
									<img id="cq" class="sampleimage" src="" jqimg="" />
								</div>
			    			</td>
			    			<td align="center">后面</td>
			    			<td class="value">
		    					<div  class="jqzoomleft">
									<img id="hm" class="sampleimage" src="" jqimg=""/>
								</div>
			    			</td>
			    		</tr>
			    	</table>
				</div>
			</div>
		</div>
	</div>
	<div id="searchfooter" style="text-align:right;padding: 0px 10px">
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="saveDate()"  data-options="iconCls:'icon-page_save',plain:true" >保存</a>
		<span class="search-btn-separator"></span>
		<a href="javascript:history.go(-1)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true">返回</a>
	</div>
</body>
</html>

<script type="text/javascript">
	$(function() {
			//计算总数
			$('#chineseNum').textbox('textbox').bind('blur', function() {  
				var num1 = $("#chineseNum").textbox('getValue'); //获取第一个输入框的值
				var num2 = $("#foreignNum").textbox('getValue');  //获取第二个输入框的值
				if(num1 != null && num1 != ""){
				    num1 = parseInt(num1);  //转换为整数
				}else{
					num1 = 0;
				}
				if(num2 != null && num2 != ""){
					num2 = parseInt(num2);  //转换为整数
				}else{
					num2 = parseInt(0);
				}
			    $("#totalNum").textbox('setValue',num1 + num2);
		     });
			
			$('#foreignNum').textbox('textbox').bind('blur', function() {  
				var num1 = $("#chineseNum").textbox('getValue'); //获取第一个输入框的值
				var num2 = $("#foreignNum").textbox('getValue');  //获取第二个输入框的值
				if(num1 != null && num1 != ""){
				    num1 = parseInt(num1);  //转换为整数
				}else{
					num1 = 0;
				}
				if(num2 != null && num2 != ""){
					num2 = parseInt(num2);  //转换为整数
				}else{
					num2 = 0;
				}
			    $("#totalNum").textbox('setValue',num1 + num2);
		     }); 
		
		//车牌号加onChange方法
		$('#carNo').textbox({
	        onChange: function(n,o) {
	        	changeCarNo();
	        }
	    });
		
		var carNo = $("#carNo").textbox('getValue');
		if(carNo != ""){
			loadPic(carNo);
		}else{
			$("#showState").val("1");
			$("#picTable").hide();
		}
		$("#entryTime").datetimebox("setValue",dtbInitDate(new Date()));
	});
	
	//防止二次提交
	var submitState = true;
	function saveDate(){
		var isValid = $("#editForm").form('validate');
		if(submitState && isValid){
			submitState = false;
			doSave();
		}
	}
	//保存
	function doSave(){
		var showState = $("#showState").val();
		var record=form2Json('editForm');
		$.ajax({
			type : 'post',
			url :  '${basePath}/bus/enterCard/save.do',
			data : "data="+JSON.stringify(record)+"&showState="+showState,
			dataType:"json",
			success : function(msg) {
				$.each(msg,function(i,n){
            		if(n.message == "success"){
            			$.messager.alert("消息", "保存成功！");
            			setTimeout(function () {
            				window.location.href="${basePath}/bus/enterCard/index.do";
            			}, 1000);
            		}else{
            			$.messager.alert('消息', n.errMsg);
            		}
               });
			}
		});
	}
	
	//修改车牌号
	function changeCarNo(){
		var carNo = $("#carNo").textbox('getValue');
		if(carNo != ""){
			loadPic(carNo);
		}
	}
	
	//导入图片
	function loadPic(carNo){
		$.ajax({
			type : 'post',
			url :  '${basePath}/bus/enterCard/loadPic.do',
			data : "carNo="+carNo,
			dataType:"json",
			success : function(msg) {
				$.each(msg,function(i,n){
            		if(n.message == "success"){
            			$("#zm").attr('src','${basePath}'+n.zm);
            			$("#zm").attr('jqimg','${basePath}'+n.zm);
            			$("#hm").attr('src','${basePath}'+n.hm);
            			$("#hm").attr('jqimg','${basePath}'+n.hm);
            			$("#cq").attr('src','${basePath}'+n.cq);
            			$("#cq").attr('jqimg','${basePath}'+n.cq);
            			$("#ch").attr('src','${basePath}'+n.ch);
            			$("#ch").attr('jqimg','${basePath}'+n.ch);
            			$("#showState").val("2");
            			$("#picTable").show();
            		}else if(n.message == "error"){
            			$("#showState").val("1");
            			$("#picTable").hide();
            		}else{
            			$("#showState").val("1");
            			$("#picTable").hide();
            			$.messager.alert('消息', n.errMsg);
            		}
               });
			}
		});
	}
</script>
